<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>完善当当购物车页面</title>
    <link type="text/css" rel="stylesheet" href="css/cartStyle.css" />
    <script type="text/javascript">
    	var sum=0;
    	function minus(){
    		var prices=document.getElementsByName("price")[0].value;
    		var count=parseInt(document.getElementsByName("amount")[0].value)-1;
    		if(count<1){
    			alert("不能再减了,在减就没有了!");
    		}else{
    			document.getElementsByName("amount")[0].value=count;
    			var totals=parseFloat(prices*count);
    			document.getElementById("price0").innerHTML="$"+totals;
    		}
    		total();
    	}
    	
    		function plus(){
    		var prices=document.getElementsByName("price")[0].value;
    		var count=parseInt(document.getElementsByName("amount")[0].value)+1;
    			document.getElementsByName("amount")[0].value=count;
    			var totals=parseFloat(prices*count);
    			document.getElementById("price0").innerHTML="$"+totals;
    			total();
    	}
    		
    		function minus1(){
    		var prices=document.getElementsByName("price")[1].value;
    		var count=parseInt(document.getElementsByName("amount")[1].value)-1;
    		if(count<1){
    			alert("不能再减了,在减就没有了!");
    		}else{
    			document.getElementsByName("amount")[1].value=count;
    			var totals=parseFloat(prices*count);
    			document.getElementById("price1").innerHTML="$"+totals;
    		}
    		total();
    	}
    		
    		function plus1(){
    		var prices=document.getElementsByName("price")[1].value;
    		var count=parseInt(document.getElementsByName("amount")[1].value)+1;
    			document.getElementsByName("amount")[1].value=count;
    			var totals=parseFloat(prices*count);
    			document.getElementById("price1").innerHTML="$"+totals;
    			total();
    	}
    		function total(){
    			var price=document.getElementsByName("price");
    			var count=document.getElementsByName("amount");
    			var sum=0;
    			for(var i=0;i<price.length;i++){
    				sum+=price[i].value*count[i].value;
    			}
    			document.getElementById("totalPrice").innerHTML="$"+sum;
    		}
    		function inia(){
    			var sum=0;
    			var count=document.getElementsByName("amount");
    			var price=document.getElementsByName("price");
    			for(var i=0;i<count.length;i++){
    				document.getElementsByName("amount")[i].value=1;
    				sum+=price[i].value*1;
    			}
    			document.getElementById("totalPrice").innerHTML="$"+sum;
    		}
    </script>
</head>
<body onload="inia()">

<div class="content">
    <div class="logo">
        <img src="img/dd_logo.jpg"><span>关闭</span>
    </div>
    <div class="cartList">
        <ul>
            <li>¥<input type="text" name="price" value="21.90"></li>
            <li><input type="button" name="minus" value="-" onclick="minus()"><input type="text" name="amount" value="1"><input type="button" name="plus" value="+" onclick="plus()"></li>
            <li id="price0">¥21.90</li>
            <li><p>移入收藏</p><p>删除</p></li>
        </ul>
        <ul>
            <li>¥<input type="text" name="price" value="24.00"></li>
            <li><input type="button" name="minus" value="-" onclick="minus1()"><input type="text" name="amount" value="1"><input type="button" name="plus" value="+" onclick="plus1()"></li>
            <li id="price1">¥24.00</li>
            <li><p>移入收藏</p><p>删除</p></li>
        </ul>
        <ol>
            <li id="totalPrice">&nbsp;</li>
            <li><span onclick="total()">结 算</span></li>
        </ol>
    </div>
</div>
</body>
</html>